package com.huffman.smart_picture.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huffman.smart_picture.domain.entity.SpaceUser;
import com.huffman.smart_picture.domain.vo.space.SpaceUserVo;
import com.huffman.smart_picture.service.SpaceUserService;
import com.huffman.smart_picture.mapper.SpaceUserMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author Administrator
 * @description 针对表【space_user】的数据库操作Service实现
 * @createDate 2025-06-28 18:24:12
 */
@Service
public class SpaceUserServiceImpl extends ServiceImpl<SpaceUserMapper, SpaceUser>
        implements SpaceUserService {

    @Override
    public Map<Long, Integer> getSpaceUserRole(Long userId) {
        Map<Long, Integer> spaceUserRoleMap = lambdaQuery().eq(SpaceUser::getUserId, userId)
                .list()
                .stream()
                .collect(Collectors.toMap(SpaceUser::getSpaceId, SpaceUser::getSpaceRole));
        return Optional.of(spaceUserRoleMap).orElse(new HashMap<>());
    }

    @Override
    public boolean SpaceUserExist(Long spaceId, Long userId) {
        return lambdaQuery().eq(SpaceUser::getSpaceId, spaceId)
                .eq(SpaceUser::getUserId, userId)
                .exists();
    }
    @Override
    public List<SpaceUserVo> getSpaceUserList(Long spaceId) {
        return this.getBaseMapper().getSpaceUserList(spaceId);
    }
    
    @Override
    public List<String> getSpaceUserAvatar(Long spaceId, Integer limit) {
        return this.getBaseMapper().getSpaceUserList(spaceId)
                .stream()
                .map(SpaceUserVo::getAvatar)
                .limit(limit)
                .collect(Collectors.toList());
    }


}




